package org.come.control;

import java.util.ArrayList;
import java.util.List;

import org.come.Frame.ZhuFrame;
import org.come.action.FromServerAction;

import com.tool.btn.VipShopBtn;

public class ViconControl implements FromServerAction {

    @Override
    public void controlMessFromServer(String mes, String type) {
        String[] split = mes.split("\\|");
        List<VipShopBtn> btnListVicon = ZhuFrame.getZhuJpanel().getBtnListVicon();
        if(btnListVicon== null){
            btnListVicon = new ArrayList<>();
            ZhuFrame.getZhuJpanel().setBtnListVicon(btnListVicon);
        }
        S:for (int i = 0; i < split.length; i++) {
            String substring = split[i].substring(1);
            for (int j = 0; j < btnListVicon.size(); j++) {
                if(btnListVicon.get(j).getVicon().equals(substring)){
                    if(split[i].startsWith("R")){
                        btnListVicon.remove(j);
                        ZhuFrame.getZhuJpanel().remove(btnListVicon.get(j));
                    }
                    continue S;
                }
            }
            if(split[i].startsWith("A")){
//                VipShopBtn btn = new VipShopBtn("skin/8100226/button/vicon"+substring+".png", 1, 55, substring);
//                btn.setBounds(200, 300, 20, 20);
//                ZhuFrame.getZhuJpanel().add(btn);
//                btnListVicon.add(btn);
            }
        }
        if(ZhuFrame.getZhuJpanel().getShowVipBtn()!=null) {
        	boolean is = ZhuFrame.getZhuJpanel().getShowVipBtn().isIs();
        	for (int i = 0; i < btnListVicon.size(); i++) {
        		VipShopBtn vipShopBtn = btnListVicon.get(i);
        		vipShopBtn.setBounds(19 + 60 * ((2+i) % 3), 72+(53-vipShopBtn.getIcon().getIconHeight())/2+(i+2)/3*55, vipShopBtn.getIcon().getIconWidth(), vipShopBtn.getIcon().getIconHeight());
        		vipShopBtn.setVisible(!is);
        	}
        }
    }
}
